<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>熔断器：微服务架构的守护者</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .state-card {
            background: white;
            border-radius: 20px;
            padding: 2rem;
            position: relative;
            overflow: hidden;
        }
        
        .state-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 5px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        }
        
        .number-circle {
            width: 50px;
            height: 50px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        .section-title {
            position: relative;
            display: inline-block;
            margin-bottom: 2rem;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border-radius: 15px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        .floating {
            animation: float 3s ease-in-out infinite;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 tracking-tight">
                    <i class="fas fa-shield-alt mr-4"></i>熔断器
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">微服务架构的守护者</p>
                <div class="max-w-3xl mx-auto">
                    <p class="text-lg leading-relaxed opacity-80">
                        通过预防性保护、快速故障响应和智能恢复机制，提高系统的可靠性和稳定性，
                        避免单个服务故障引发连锁反应，减少系统的总体风险。
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- 核心概念可视化 -->
        <section class="mb-16">
            <div class="bg-white rounded-3xl shadow-xl p-8">
                <h2 class="section-title text-3xl font-bold text-gray-800 mb-8">
                    <i class="fas fa-diagram-project mr-3 text-purple-600"></i>熔断器工作原理
                </h2>
                <div class="mermaid">
                    graph LR
                        A[客户端请求] --> B{熔断器}
                        B -->|闭合状态| C[正常调用服务]
                        B -->|打开状态| D[快速失败]
                        B -->|半开状态| E[部分请求通过]
                        C -->|成功| F[返回结果]
                        C -->|失败超过阈值| G[切换到打开状态]
                        E -->|成功| H[恢复到闭合状态]
                        E -->|失败| I[返回打开状态]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style B fill:#bbf,stroke:#333,stroke-width:4px
                        style D fill:#f66,stroke:#333,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- 核心作用 -->
        <section class="mb-16">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-8">
                <i class="fas fa-star mr-3 text-purple-600"></i>核心作用
            </h2>
            
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <!-- 防止服务雪崩 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-6">
                    <div class="feature-icon">
                        <i class="fas fa-snowflake"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">防止服务雪崩效应</h3>
                    <p class="text-gray-600 mb-4">
                        熔断器可以防止一个服务的故障传递到其他服务，及时"熔断"对故障服务的调用，避免故障请求持续传递并导致整个系统的崩溃。
                    </p>
                    <div class="bg-purple-50 rounded-lg p-4">
                        <p class="text-sm text-purple-700">
                            <i class="fas fa-lightbulb mr-2"></i>
                            <strong>示例：</strong>服务A依赖服务B，当B故障时，熔断器自动阻止对B的请求，保护A不受影响。
                        </p>
                    </div>
                </div>

                <!-- 降低故障传播 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-6">
                    <div class="feature-icon" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                        <i class="fas fa-virus-slash"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">降低系统故障传播</h3>
                    <p class="text-gray-600 mb-4">
                        当调用失败超过阈值时，熔断器跳转到"断路器"状态，暂停对该服务的调用，防止失败请求占用系统资源。
                    </p>
                    <div class="bg-blue-50 rounded-lg p-4">
                        <p class="text-sm text-blue-700">
                            <i class="fas fa-lightbulb mr-2"></i>
                            <strong>示例：</strong>服务B不可用时，熔断器切换到断路状态，减少对B的频繁请求。
                        </p>
                    </div>
                </div>

                <!-- 快速失败与恢复 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-6">
                    <div class="feature-icon" style="background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">快速失败与快速恢复</h3>
                    <p class="text-gray-600 mb-4">
                        熔断器能在服务出现问题时迅速反应，避免系统过度负载，并在服务恢复后尽快恢复正常操作。
                    </p>
                    <div class="bg-yellow-50 rounded-lg p-4">
                        <p class="text-sm text-yellow-700">
                            <i class="fas fa-lightbulb mr-2"></i>
                            <strong>示例：</strong>故障期间阻止请求，恢复后自动恢复请求，系统快速回归正常。
                        </p>
                    </div>
                </div>

                <!-- 实时监控 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-6">
                    <div class="feature-icon" style="background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">实时监控与故障检测</h3>
                    <p class="text-gray-600 mb-4">
                        通过监控请求成功率和响应时间等指标，实时检测服务健康状态，根据预设规则做出熔断决策。
                    </p>
                    <div class="bg-green-50 rounded-lg p-4">
                        <p class="text-sm text-green-700">
                            <i class="fas fa-lightbulb mr-2"></i>
                            <strong>示例：</strong>统计服务成功率，低于阈值或响应过慢时触发熔断。
                        </p>
                    </div>
                </div>

                <!-- 提高用户体验 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-6">
                    <div class="feature-icon" style="background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);">
                        <i class="fas fa-smile"></i>
                    </div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">提高用户体验</h3>
                    <p class="text-gray-600 mb-4">
                        通过熔断机制避免长时间的请求超时和失败，快速响应并返回失败信息，提升用户体验。
                    </p>
                    <div class="bg-orange-50 rounded-lg p-4">
                        <p class="text-sm text-orange-700">
                            <i class="fas fa-lightbulb mr-2"></i>
                            <strong>示例：</strong>用户能及时获知服务不可用，而不是等待过长的超时响应。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- 工作状态 -->
        <section class="mb-16">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-8">
                <i class="fas fa-toggle-on mr-3 text-purple-600"></i>熔断器的工作状态
            </h2>
            
            <div class="grid md:grid-cols-3 gap-8">
                <!-- 闭合状态 -->
                <div class="state-card floating" style="animation-delay: 0s;">
                    <div class="number-circle">1</div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-3">
                        <i class="fas fa-check-circle text-green-500 mr-2"></i>闭合状态
                    </h3>
                    <p class="text-gray-600 leading-relaxed">
                        默认状态，所有请求都会被发送到被保护的服务。熔断器监控请求的成功率和响应时间，如果失败率超出阈值，熔断器会切换到"打开"状态。
                    </p>
                </div>

                <!-- 打开状态 -->
                <div class="state-card floating" style="animation-delay: 0.5s;">
                    <div class="number-circle">2</div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-3">
                        <i class="fas fa-times-circle text-red-500 mr-2"></i>打开状态
                    </h3>
                    <p class="text-gray-600 leading-relaxed">
                        熔断器在此状态下停止所有对被保护服务的请求，快速返回失败响应。熔断器会周期性地尝试恢复，如果服务正常，它会切换回"半开"状态。
                    </p>
                </div>

                <!-- 半开状态 -->
                <div class="state-card floating" style="animation-delay: 1s;">
                    <div class="number-circle">3</div>
                    <h3 class="text-2xl font-bold text-gray-800 mb-3">
                        <i class="fas fa-adjust text-yellow-